<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="系统状态" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择系统状态" clearable size="small">
          <el-option
            v-for="dict in typeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="备注" prop="remarks">
        <el-input
          v-model="queryParams.remarks"
          placeholder="请输入备注"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:timeMonitoring:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		      :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:timeMonitoring:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="timeMonitoringList" border size="mini" stripe @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id" align="center" prop="id" v-if="false"/>
      <el-table-column label="头像" align="center" prop="avatarUrl" >
        <template slot-scope="scope">
          <img :src="scope.row.avatarUrl" alt="上传人头像" height="20%" width="20%" v-if="scope.row.avatarUrl" @click="showImg(scope.row.avatarUrl)">
        </template>
      </el-table-column>
      <el-table-column label="上传人姓名" align="center" prop="uploadUser" />
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="扫码时上传的照片" align="center" prop="timeUrl" >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-picture"
            @click="showImg(scope.row.timeUrl)"
          >点击查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="多个经度" align="center" prop="gpsxs" />
      <el-table-column label="多个维度" align="center" prop="gpsys" />
      <el-table-column label="系统状态" align="center" prop="type" :formatter="typeFormat" />
      <el-table-column label="备注" align="center" prop="remarks" />
      <el-table-column label="起点上传时间" align="center" prop="createtime"  width="135">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createtime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="终点上传时间" align="center" prop="endCreatetime"  width="135">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endCreatetime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:timeMonitoring:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:timeMonitoring:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改扫码信息管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="30%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules"   label-width="120px">
        <el-form-item label="系统状态" prop="type">
          <el-select v-model="form.type" placeholder="请选择系统状态" style="width: 100%;">
            <el-option
              v-for="dict in typeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 头像 -->
    <el-dialog :title="imgTitle" :visible.sync="imgOpen" v-if="imgOpen" width="40%" append-to-body>
      <show-imgs :imgs="imgUrl"></show-imgs>
    </el-dialog>



  </div>
</template>

<script>
import { listTimeMonitoring, getTimeMonitoring, delTimeMonitoring, addTimeMonitoring, updateTimeMonitoring, exportTimeMonitoring } from "@/api/system/timeMonitoring";
import AMap from "@/components/aMap";
import ShowImgs from "@/components/ShowImgs";

export default {
  name: "TimeMonitoring",
  components: {
    ShowImgs,
    AMap,
  },
  data() {
    return {
	  //按钮loading
	  buttonLoading: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //轨迹回放
      mapOpen: false,
      imgOpen: false,
      imgTitle: "",
      imgUrl: "",
      lnglats: [],//地图中心
      // 扫码信息管理表格数据
      timeMonitoringList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 系统状态字典
      typeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: undefined,
        remarks: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("time_monitoring_type").then(response => {
      this.typeOptions = response.data;
    });
  },
  methods: {
    /** 查询扫码信息管理列表 */
    getList() {
      this.loading = true;
      listTimeMonitoring(this.queryParams).then(response => {
        this.timeMonitoringList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 系统状态字典翻译
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.type);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.imgOpen = false;
      this.mapOpen = false;
      this.reset();
    },
    //查看详情图
    showImg(imgUrl){
      this.imgOpen = true;
      this.imgTitle = "图片详情";
      this.imgUrl = imgUrl;
    },
    //查看轨迹回放
    showGuiji(row){
      var gspxs = row.gpsxs.split(",");
      var gspys = row.gpsys.split(",");
      var position = []
      for(var i=0;i<gspxs.length;i++){
        position[i] = [gspxs[i],gspys[i]]
      }
      console.log(position)
      this.lnglats = position;
      this.mapOpen = true;
      this.title = "位置标记";
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        communityId: undefined,
        qrId: undefined,
        phone: undefined,
        timeUrl: undefined,
        gpsxs: undefined,
        gpsys: undefined,
        type: undefined,
        remarks: undefined,
        uploadTime: undefined,
        createtime: undefined,
        updatetime: undefined,
        endCreatetime: undefined,
        endUpdatetime: undefined
      };
      this.resetForm("form");
      this.lnglats = [];
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加扫码信息管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getTimeMonitoring(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改扫码信息管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateTimeMonitoring(this.form).then(response => {
              this.buttonLoading = false;
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTimeMonitoring(this.form).then(response => {
              this.buttonLoading = false;
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除扫码信息管理编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.loading = true;
          return delTimeMonitoring(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有扫码信息管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportTimeMonitoring(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
